package servlets.admin;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import managers.EntityManagerAux;

import entities.User;

/**
 * Servlet implementation class BanUser.
 * On utilise le servlet pour banner les utilisateurs.
 */
public class BanUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BanUser() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    @EJB EntityManagerAux mng;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		List<User> lol= (List<User>) request.getSession().getAttribute("myObjectId2");
		List<User> validated = new ArrayList();
		request.getSession().removeAttribute("myObjectId2");
		//System.out.println(lol.size()+" Si existo");
		for(int i=0; i<lol.size(); i++) {
			if(request.getParameter(""+i)!= null) {
				validated.add(lol.get(i));
			}
		}
		System.out.println(validated.size());
		mng.banUsers(validated);
		String goTo="functionsAdmin.jsp";
		request.getRequestDispatcher(goTo).forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
